import typing as T
from typing_extensions import override
from io import BytesIO
from langchain_core.documents import Document
import pandas as pd
from pathlib import Path
from . import IFileLoader


class EXCELLoader(IFileLoader):
    def __init__(self): ...

    @override
    def load(
        self,
        blob: T.Union[str, Path, bytes, BytesIO],
        uuid: str,
        file_name: str = None,
        **kwargs,
    ) -> T.List[Document]:
        self.setUuid(uuid)
        blob = self.verify(blob)
        df = pd.read_excel(blob, sheet_name=None)
        docs = []
        for sheet_name, df in df.items():
            docs.extend(
                self._process_table_data(
                    df, sheet_name, file_type="excel", file_name=file_name
                )
            )
        return docs
